<?php
declare(strict_types=1);

namespace SixShop\Payment\Controller;

use SixShop\Core\Helper;
use SixShop\Core\Request;
use SixShop\Payment\Config;
use SixShop\Payment\PaymentManager;
use think\Response;
use think\response\Json;
use function SixShop\Core\success_response;

class PaymentController
{
    public function index(PaymentManager $paymentManager, Config $config, Request $request): Response
    {
        $env = $request->header('env');
        $payments = array_column($paymentManager->getAllPayment(), null, 'id');
        $result = [];
        foreach ($payments as $id => $payment) {
            if ($env == null || in_array($env, $config->getConfig('supported_env_' . $id, []))) {
                $result[] = $payment;
            }
        }
        return success_response($result);
    }
}